<?php
/**
 * brandcontroller.php
 * 
 * Create on 2015-04-02
 * Create by yuebin
 */
namespace haibao\cms\business\control\pc\index;
use \haibao\cms\business\control\pc\entity\ArticleEntity;

class BrandController extends IndexController{

	const BRAND_TAG = 955;
	const TRENDS_BLOG_CATEGORY = 93;
	const TRENDS_SHOW = 324;
	private static $brandType = array(
			'1'=>"女装",
			'20'=>"男装",
			'3'=>"手袋 / 鞋靴 / 箱包",   //24->3
			'2'=>"丝巾 / 帽袜 / 配饰",
			'17'=>"婚纱礼服",
			'29'=>"童装",
			'30'=>"内衣",
			'19'=>"牛仔丹宁",
			'23'=>"运动/户外服饰",
			'4'=>"珠宝 / 钟表",  //5-》4
			'5'=>"眼镜",//查看眼镜有多少个
			'8'=>"美妆",	//9-》8
			'12'=>"男士护肤 / 香水",
			'6'=>"洗护",	//	13，7-》6
			'16'=>"家居饰品",
			'18'=>"美食与美酒",
			'21'=>"汽车",
			'14'=>"潮流数码",
			'22'=>"生活电器",
			'15'=>"卡通玩偶 / 手绘插画"
		);
	public function __construct($updateTime = null,$controlId,$isPublish){

		$this->conditionTagId = self::BRAND_TAG;
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	/**
	 * 显示模版内容（模版动态数据的绑定和模版输出）
	 * @param : String $content
	 * @param : Array $controlData;
	 */
	public function displayTemplateHtml(){

		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		if($controlData['manual']){
			// 第一屏
			$this->getFirstActualData($controlData['manual']);
		}
		$brandType = self::$brandType;
		$this->assign('brandType',$brandType);
		$this->assign('attentionType', \haibao\www\model\data\Favorite::ATTENTION_TYPE_BRAND);

		$this->assign('channelUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BRANDS));
		$this->assign('brandChannelUrl', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_BRAND));
		
		$this->assign('wordLinkList',$this->getWordLinkList($controlData['auto'],self::getTagChannel($this->conditionTagId)));
		
		$path = $this->generateHtmlPath(__CLASS__);
		$this->generateHtml($path,$content);
		
		$content = $this->getHtml($path);
		$content = $this->replaceCDNLink($content);	
		return $content;
	}
	/**
	 * 获取品牌文章第一屏数据
	 * 获取品牌下的所有标签
	 * 根据所有的标签取出最新的7篇文章和对应的标签（做为keywords）
	 * @param : $dataCondition 数据条件
	 */
	public function getFirstActualData($dataCondition){
		
		$articleEntity = new ArticleEntity();
		$articleEntity->setLevel($dataCondition['level']);
		$articleEntity->setBigLevel($dataCondition['biglevel']);
		$articleEntity->setLimit($dataCondition['limit']);
		$articleEntity->setIsProImage(true);
		$articleEntity->setIsLeftJoinTag(true);
		$articleEntity->setIsPrimaryTag(false);
		$articleEntity->setIsConditionTag(true);
		$articleEntity->setIsReturnTag(true);
		$articleEntity->setIsImageColl(true);
		$articleEntity->setSource(__CLASS__);
		$articleEntity->setTagIds($this->conditionTagId);
		$articleEntity->setIsDebug(false);
		$articleEntity->setIsOnlyReturnPrimaryTag(true);
		$articleEntity->setProImageLevel(array(\haibao\cms\model\data\ArticleProImage::Level_FOUR));
		
		$this->articleAction->setArticleEnity($articleEntity);
		list($articles,$imageColls) = $this->articleAction->getListForNew();
		$mergeData = $this->mergeData($articles['list'],$imageColls['list'],$articleEntity->getLimit());
		list($firstLeftArticle,$firstRightArticle) = $this->packageMergeData(self::PACKAGE_DATA_TYPE_INDEX_BRAND_OR_BEAUTY_OR_LIFT, $mergeData, $articles, $imageColls);
		$this->assign('firstLeftArticle',json_decode(json_encode(array_values($firstLeftArticle))));
		$this->assign('firstRightArticle', json_decode(json_encode(array_values($firstRightArticle))));
	}
}